<?php
class Proveedores extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->helper(array('url'));
        $this->load->library(array('session', 'r_session', 'form_validation', 'email'));
        $this->r_session->check($this->session->all_userdata());
        $this->load->model(array(
            'proveedores_model'
        ));
    }
    
    public function index() {
        $session = $this->session->all_userdata();
        $session['title'] = 'Listado de Proveedores';
        $data['proveedores'] = $this->proveedores_model->get_proveedores();
        
        $this->load->view('layout/header', $session);
        $this->load->view('proveedores/index', $data);
        $this->load->view('layout/footer');
    }
    
    public function agregar() {
        $session = $this->session->all_userdata();
        $session['title'] = 'Agregar Proveedor';
        
        $this->form_validation->set_rules('proveedor', 'Razón Social', 'required');
        
        if($this->form_validation->run() == FALSE) {
            
        } else {
            $datos = array(
                'proveedor' => $this->input->post('proveedor'),
                'direccion' => $this->input->post('direccion'),
                'telefono' => $this->input->post('telefono')
            );
            
            $this->proveedores_model->set_proveedor($datos);
            
            redirect('/proveedores/', 'refresh');
        }
        
        $this->load->view('layout/header', $session);
        $this->load->view('proveedores/agregar');
        $this->load->view('layout/footer');
    }
}
?>
